package com.jdrx.sw.sewage.dao;

import com.jdrx.sw.sewage.beans.anno.MapF2F;
import com.jdrx.sw.sewage.beans.dto.AiModelQueryDTO;
import com.jdrx.sw.sewage.beans.entity.DeviceTimeDataPO;
import com.jdrx.sw.sewage.beans.vo.BigScreeneFfluentVO;
import com.jdrx.sw.sewage.beans.vo.DoAndMlssVO;
import com.jdrx.sw.sewage.beans.vo.SimpleRealtimeDataVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Mapper
public interface DeviceTimeDataDAO {
    int insert(DeviceTimeDataPO record);

    List<DeviceTimeDataPO> selectAll();

    int batchInsert(Map<String, Object> params);
    
    Integer sysTestCloseAlarm(@Param("dataNode") String dataNode,
                              @Param("deviceId") Long deviceId,
                              @Param("startTime") LocalDateTime startTime,
                              @Param("gatherDevPointValue") String gatherDevPointValue,
                              @Param("val") BigDecimal val,
                              @Param("val2") BigDecimal val2);

    List<DeviceTimeDataPO> findRealTimeLastPacksByParams(Map<String, Object> params);

    List<DeviceTimeDataPO> findRealTimeFirstPacksByParams(Map<String, Object> params);

    List<DeviceTimeDataPO> findRealTimeFirstPacksByParams2(Map<String, Object> params);

    List<DeviceTimeDataPO> selectRealTimeLastPacksByParams(Map<String, Object> params);

    List<DeviceTimeDataPO> selectRealTimeLastPacksByParams2(Map<String, Object> params);

    int batchInsertHistory(Map<String, Object> params);

    List<DeviceTimeDataPO> energyReport(@Param("dataNode") String dataNode,
                                        @Param("key") String key,
                                        @Param("strTime") String strTime,
                                        @Param("strDay") String strDay);

    List<DeviceTimeDataPO> energyReportFirst(@Param("dataNode") String dataNode,
                                             @Param("devId") Long devId,
                                             @Param("strTime") String strTime,
                                             @Param("strDay") String strDay);

    List<DeviceTimeDataPO> findLastPacks(@Param("dataNode") String dataNode);

    List<Double> selectNearbyFiveByDevId(@Param("devId") Long devId, @Param("gdpv") String gdpv, @Param("dataNode") String dataNode);

    BigScreeneFfluentVO findRealTimeCrruDayByParams();

    BigScreeneFfluentVO findRealTimeCrrumonthByParams(@Param("time") String time);

    /**
     * 根据匹配的年月日+小时查询碳源加药间1#的瞬时流量点位
     */
    List<SimpleRealtimeDataVO> findTyjy1ll(@Param("time") String time);

    List<DeviceTimeDataPO> findThreeDayData(@Param("dataNode") String dataNode,
                                            @Param("time") Date time);

    void batchDeleteByTime(Map<String, Object> params);

    Boolean deviceTimeDataBackup2();

    @MapF2F(isAllowKeyRepeat = true)
    Map<String, Double> findOneHourAvgPars(AiModelQueryDTO aiModelQueryDTO);

    @MapF2F(isAllowKeyRepeat = true)
    Map<String, Double> findOneHourSumPars(AiModelQueryDTO dto);

    @MapF2F(isAllowKeyRepeat = true)
    Map<String, Double> findWaterQualityForecast(@Param("time") LocalDateTime time);

    /**
     * 获取当前时间前一小时的累计流量
     *
     * @param startTime endTime - 1 hour
     * @param endTime   当前任务执行时间整点
     * @return
     */
    Double getHourTotalLL(@Param("startTime") LocalDateTime startTime, @Param("endTime") LocalDateTime endTime);

    List<DoAndMlssVO> findDOAndMLSS(@Param("startTime") String startTime, @Param("endTime") String endTime);
}